package com.qfjy.jms.service.impl;

import com.qfjy.config.JedisConfig;
import com.qfjy.jms.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

@Service
public class CodeServiceImp implements CodeService {
    @Autowired
    private JedisPool jedisPool;

    @Override
    public void codeMake() {

        String s =new Random().nextInt(9999)+"";
        Jedis resource = jedisPool.getResource();
        Map<String,String> code =new HashMap<>();
        code.put("code",s);
        resource.hset("msgcode",code);
        resource.expire("msgcode",20);
        resource.close();
    }

    @Override
    public Boolean codeCheck(String code) {
        Jedis resource = jedisPool.getResource();
        String hget = resource.hget("msgcode", "value");
        if (code.equals(hget)) {
            return true;
        }else {
            return false;
        }

    }


}
